﻿using Sl.Upload.Models;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sl.Upload.Help
{
    public class OtherHelp
    {
        /// <summary>
        /// 创建目录
        /// </summary>
        /// <param name="fim"></param>
        public static void CreateDirectory(FileInfoModel fim)
        {
            if (!Directory.Exists(fim.SavePath))
                Directory.CreateDirectory(fim.SavePath);
            if (fim.CutItem == null) return;
            foreach (CutInfo ci in fim.CutItem)
            {
                if (!Directory.Exists(ci.GeneratePath))
                    Directory.CreateDirectory(ci.GeneratePath);
            }
        }

        /// <summary>
        /// 创建目录
        /// </summary>
        /// <param name="path"></param>
        public static void CreateDirectory(string path)
        {
            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);
        }

        /// <summary>
        /// 验证文件是否为图片
        /// </summary>
        /// <param name="fileStream"></param>
        /// <returns></returns>
        public static bool IsImage(Stream fileStream)
        {
            try
            {
                Image.FromStream(fileStream);
                return true;
            }
            catch (Exception ex) { return false; }
        }
    }
}
